/**
 * 场景配置&路由
 * 2023/5/5
 */

const express = require("express");
const router = express.Router();
const { exec } = require('child_process')
const Result = require("../utils/Result");
const path = require('path');
router.get('/', function (req, res) {
    res.send('场景配置')
})
/**
 * 创建场景
 */
router.post('/structure', function (req, res) {
    const rootPath = path.resolve(__dirname,'..');
    console.log(rootPath);
    console.log(req.body);
    let objname = rootPath;//全景图输出路径
    let dataList = req.body;
    let stringList = ''
    dataList.forEach(e => {
        stringList += ` ${rootPath+e.url}`
    });
    console.log(stringList);
    let command = `${rootPath}\\krpano64.exe makepano -config=${rootPath}\\templates\\vtour-multires.config ${stringList}`
    console.log(command);
    exec(command, { encoding: 'utf-8' }, function (err, stot, stdr) {
        let stots = stot.replace(/[^a-zA-Z]/g, '');
        if (err) {
            return res.send('出错了' + err);
        }
        new Result('创建成功！').success(res)
    })
})

module.exports = router;